﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RBS.Common.EmailHelp
{
    public static class EmailHelp
    {
         
        #region 邮件模版
       public  static string Hotel = @"<strong>{username}，您好：</strong><br />
                            <p>
	                            您在<span style=\""color:#FF0000;\"">{webname}</span>点击了“忘记密码”找回申请，故系统自动为您发送了这封邮件。您可以点击以下链接修改您的密码：<br />
                            <a href=\""{linkurl}\"" target=\""_blank\"">{linkurl}</a> 
                            </p>
                            <hr />
                            <p>
	                            此链接有效期为{valid}天，请在{valid}天内点击链接进行修改。如果您不需要修改密码，或者您从未点击过“忘记密码”按钮，请忽略本邮件。<br />
                            任何疑问，请拨打客服热线咨询：{webtel}。谢谢您的支持！
                            </p>
                            <div style=\""text-align:right;\"">
	                            {webname} {weburl}
                            </div>";

        #endregion


       public static bool SendRegMail(SendMailModel sendMail)
        {
              var ma = new MailAttachments();
               // ma.Add(@"附件地址");
                var mail = new MailMessage {Attachments = ma};
            string htmlTemp = @"<strong>{username}，您好：</strong><br />
                            <p>
	                            您在<span style=\""color:#FF0000;\"">{webname}</span>点击了“忘记密码”找回申请，故系统自动为您发送了这封邮件。您可以点击以下链接修改您的密码：<br />
                            <a href=\""{linkurl}\"" target=\""_blank\"">{linkurl}</a> 
                            </p>
                            <hr />
                            <p>
	                            此链接有效期为{valid}天，请在{valid}天内点击链接进行修改。如果您不需要修改密码，或者您从未点击过“忘记密码”按钮，请忽略本邮件。<br />
                            任何疑问，请拨打客服热线咨询：{webtel}。谢谢您的支持！
                            </p>
                            <div style=\""text-align:right;\"">
	                            {webname} {weburl}
                            </div>";

                htmlTemp = htmlTemp.Replace("{username}", sendMail.Username);
                htmlTemp = htmlTemp.Replace("{webname}", "呷饭网");
                 htmlTemp = htmlTemp.Replace("{linkurl}", "http://hotel.rbs.com");
                 htmlTemp = htmlTemp.Replace("{valid}", "3");
                 htmlTemp = htmlTemp.Replace("{webtel}", "50706888");
                 htmlTemp = htmlTemp.Replace("{weburl}", "http://hotel.rbs.com"); 
                mail.Body = htmlTemp;
                mail.AddRecipients(sendMail.Email);
                mail.From = "etouchfood@163.com";
                mail.FromName = "呷饭网";
                mail.Subject = "欢迎加入呷饭网";
                var sp = new SmtpClient {SmtpServer = "smtp.163.com"};
                return sp.Send(mail, "etouchfood@163.com", "yitaoshifu"); 
        }


       public static bool SendRestPassWordMail(SendMailModel sendMail)
       {
           var ma = new MailAttachments();
           // ma.Add(@"附件地址");
           var mail = new MailMessage { Attachments = ma };
           string htmlTemp = @"<strong>{username}，您好：</strong><br />
                            <p>
	                            您在<span style=\""color:#FF0000;\"">{webname}</span>点击了“忘记密码”找回申请，故系统自动为您发送了这封邮件。<br />
                                   您的新密码为：{NewPassWord},请及时登录网站修改密码！ 
                            </p>
                            <hr />
                            
                            <div style=\""text-align:right;\"">
	                            {webname}<br/> 
                                {weburl}<br/> 
                                {webtel}
                            </div>";
           htmlTemp = htmlTemp.Replace("{NewPassWord}", sendMail.NewPassWord);
           htmlTemp = htmlTemp.Replace("{username}", sendMail.Username);
           htmlTemp = htmlTemp.Replace("{webname}", sendMail.Webname);
           htmlTemp = htmlTemp.Replace("{webtel}", sendMail.Webtel);
           htmlTemp = htmlTemp.Replace("{weburl}", sendMail.Weburl);
           mail.Body = htmlTemp;
           mail.AddRecipients(sendMail.Email);
           mail.From = "etouchfood@163.com";
           mail.FromName = "呷饭网";
           mail.Subject = "密码找回";
           var sp = new SmtpClient { SmtpServer = "smtp.163.com" };
           return sp.Send(mail, "etouchfood@163.com", "yitaoshifu");
       } 

        public class SendMailModel
        {
            public SendMailModel()
            {
                Webname = "呷饭网";
                Webtel = "12345678";
                Weburl = "http://www.xiafanwang.com/";
            }

            public string Email { get; set; }
            public string NewPassWord { get; set; }
            public string Username { get; set; }
            public string Webname { get; set; } 
            public string Webtel { get; set; }
            public string Weburl { get; set; }
        } 
    }
}
